package com.hw.one.collect.radar.Listener;

import com.hw.one.collect.radar.service.VideoImageService;
import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;

import javax.annotation.Resource;

/**
 * 视频分析服务接收程序
 * Created by lyk on 2017/12/18.
 * @author liyakun
 */
public class VideoImageReceiver implements ChannelAwareMessageListener {

    protected Logger log = LoggerFactory.getLogger(this.getClass());

    @Resource
    private VideoImageService videoImageService;

    @Override
    public void onMessage(Message message, Channel channel) throws Exception {
        try {

            log.info("监听到视频分析报警信息：" );
            videoImageService.videoImage(new String(message.getBody()));
        }catch (Exception e) {
            log.error("解析视频分析报警数据异常", e);
            e.printStackTrace();
        }
        // 给消息队列回应
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
